﻿namespace SourceCodeRepository.Persistence.Tests.RepositoryTest
{
    using System.IO;
    using System.Reflection;
    using Common;
    using Infra.NHibernateUnitOfWork;
    using Model;
    using NHibernate.Cfg;
   
    /// <summary>
    /// Test context used for the Unit Of Work for test repositories
    /// </summary>
    public class TestConfigurationContext : IConfigurationContext
    {
        /// <summary>
        /// Gets the configuration.
        /// </summary>
        /// <value>The configuration.</value>
        public Configuration Configuration
        {
            get
            {
                string resourceTestDirectory = Path.Combine(CommonConstants.ApplicationPath,Path.Combine(CommonConstants.ConfigurationDirectory,CommonConstants.TestDirectory));
                string testConfigurationFilePath = Path.Combine(resourceTestDirectory,CommonConstants.TestConfigurationFileName);


                Configuration config = new Configuration();
                config.Properties.Clear();

                config.SetProperty("hibernate.connection.driver_class",
                    "NHibernate.Driver.SQLite20Driver");
                config.SetProperty("hibernate.dialect", "NHibernate.Dialect.SQLiteDialect");
                config.SetProperty("hibernate.connection.connection_string",
                    "Data Source=:memory:;Version=3;New=True;");
                config.SetProperty("hibernate.cache.use_second_level_cache", "false");
                config.SetProperty("hibernate.hbm2ddl.auto", "create");

                config.AddAssembly(Assembly.GetAssembly(typeof (Language)));

                FileInfo configLog4Net = new FileInfo(testConfigurationFilePath);
                log4net.Config.XmlConfigurator.Configure(configLog4Net);
                
                return config;
            }
        }
    }
}
